import Vue from 'vue'
import VueRouter from 'vue-router'
import index from '../views/index'
import Home from '../views/Home'
import task from '../views/task/task'
import taskList from '../views/task/children/taskList'
import user from "../views/user/user"
import dashboard from "../views/user/children/dashboard"
import accountdetail from "../views/user/children/accountdetail"
import mylisting from "../views/user/children/mylisting"
import payment from "../views/user/children/payment"
import postad from "../views/post-ad"
import single_product from "../views/single_product"

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'index',
    component: index,
    redirect: '/home',
    children: [
      {path: 'home', component: Home},
      {
        path: '/task',
        name: 'task',
        component: task,
        redirect: '',
        children: [
          {path: '', name: 'taskList', component: taskList}
        ]
      },
      {
        path: 'user',
        name: 'user',
        component: user,
        redirect: '/user/dashboard',
        children: [
          {path: 'dashboard', name: 'dashboard', component: dashboard},
          {path: 'account', name: 'account', component: accountdetail},
          {path: 'mlist', name: 'mlist', component: mylisting},
          {path: 'payment', name: 'payment', component: payment}
        ]
      },
      {path:'postad',name:'postad',component:postad},
      {path:'single_product',name:'single_product',component:single_product}
    ]
  },
  {path: '*', redirect: '/home'}
]
const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error=> error)
}

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
